"""author: wangxin
   data: 2021/11/21
   project: 王鑫 文件操作.py
"""

d1 = {}
with open('Walden.txt', 'r', encoding='UTF-8') as file:
    lst = file.readlines()

for i in lst:
    i.upper()
    for j in i.split(sep=' '):
        if j in d1:
            d1[j] += 1
        else:
            d1[j] = 1

word = sorted(d1.items(),
            key=lambda x: x[1], reverse=True)[:10]

print("单词出现前十的是", word)
